package leetcode81_90;

/**
 * @author shhjiang_001
 * @create 2020-07-01 13:54
 */
public class Solution88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] ints = new int[m + n];
        if(n == 0) return;
        int k = 0;
        int i = 0;
        int j = 0;
        if(m == 0){
            while (i < n){
                nums1[i] = nums2[i];
                i++;
            }
            return;
        }

        while (i < m || j < n ){
            if (nums1[i] <= nums2[j] ){
                ints[k] = nums1[i];
                k++;
                i++;
            }else {
                ints[k] = nums2[j];
                k++;
                j++;
            }
            if (i == m){
                while (j < n){
                    ints[k] = nums2[j];
                    k++;
                    j++;
                }
            }
            if (j == n){
                while (i < m){
                    ints[k] = nums1[i];
                    k++;
                    i++;
                }
            }

        }
        for (int l = 0; l < m+n; l++) {
            nums1[l] = ints[l];
        }

    }
}
